package com.ds.lens.data.service.dao.sql.provider;

import com.ds.lens.data.service.dao.entity.LensDashboard;
import org.apache.ibatis.jdbc.SQL;

public class LensDashboardSqlProvider {

    public String insertSelective(LensDashboard record) {
        SQL sql = new SQL();
        sql.INSERT_INTO("lens_dashboard");

        if (record.getId() != null) {
            sql.VALUES("id", "#{id,jdbcType=BIGINT}");
        }

        if (record.getName() != null) {
            sql.VALUES("name", "#{name,jdbcType=VARCHAR}");
        }

        if (record.getType() != null) {
            sql.VALUES("type", "#{type,jdbcType=INTEGER}");
        }

        if (record.getShared() != null) {
            sql.VALUES("shared", "#{shared,jdbcType=INTEGER}");
        }

        if (record.getOpenedCount() != null) {
            sql.VALUES("opened_count", "#{openedCount,jdbcType=BIGINT}");
        }

        if (record.getExpertTemplate() != null) {
            sql.VALUES("expert_template", "#{expertTemplate,jdbcType=INTEGER}");
        }

        if (record.getPanelContent() != null) {
            sql.VALUES("panel_content", "#{panelContent,jdbcType=VARCHAR}");
        }

        if (record.getApplicationId() != null) {
            sql.VALUES("application_id", "#{applicationId,jdbcType=INTEGER}");
        }

        if (record.getMonitorId() != null) {
            sql.VALUES("monitor_id", "#{monitorId,jdbcType=BIGINT}");
        }

        if (record.getMonitorVersion() != null) {
            sql.VALUES("monitor_version", "#{monitorVersion,jdbcType=INTEGER}");
        }

        if (record.getEventId() != null) {
            sql.VALUES("event_id", "#{eventId,jdbcType=VARCHAR}");
        }
        if (record.getMonitorWindowTime() != null) {
            sql.VALUES("monitor_window_time", "#{monitorWindowTime,jdbcType=INTEGER}");
        }


        if (record.getCreator() != null) {
            sql.VALUES("creator", "#{creator,jdbcType=VARCHAR}");
        }

        if (record.getCreatedTime() != null) {
            sql.VALUES("created_time", "#{createdTime,jdbcType=TIMESTAMP}");
        }

        if (record.getMender() != null) {
            sql.VALUES("mender", "#{mender,jdbcType=VARCHAR}");
        }

        if (record.getModifiedTime() != null) {
            sql.VALUES("modified_time", "#{modifiedTime,jdbcType=TIMESTAMP}");
        }

        if (record.getIsDelete() != null) {
            sql.VALUES("is_delete", "#{isDelete,jdbcType=BIT}");
        }

        return sql.toString();
    }

    public String updateByPrimaryKeySelective(LensDashboard record) {
        SQL sql = new SQL();
        sql.UPDATE("lens_dashboard");


        if (record.getName() != null) {
            sql.SET("name = #{name,jdbcType=BIGINT}");
        }

        if (record.getType() != null) {
            sql.SET("type = #{type,jdbcType=INTEGER}");
        }

        if (record.getShared() != null) {
            sql.SET("shared = #{shared,jdbcType=INTEGER}");
        }

        if (record.getOpenedCount() != null) {
            sql.SET("opened_count = #{openedCount,jdbcType=BIGINT}");
        }

        if (record.getExpertTemplate() != null) {
            sql.SET("expert_template = #{expertTemplate,jdbcType=INTEGER}");
        }
        if (record.getPanelContent() != null) {
            sql.SET("panel_content = #{panelContent,jdbcType=VARCHAR}");
        }
        if (record.getApplicationId() != null) {
            sql.SET("application_id = #{applicationId,jdbcType=INTEGER}");
        }

        if (record.getMonitorId() != null) {
            sql.SET("monitor_id = #{monitorId,jdbcType=BIGINT}");
        }

        if (record.getMonitorVersion() != null) {
            sql.SET("monitor_version = #{monitorVersion,jdbcType=INTEGER}");
        }

        if (record.getEventId() != null) {
            sql.SET("event_id = #{eventId,jdbcType=VARCHAR}");
        }

        if (record.getMonitorWindowTime() != null) {
            sql.SET("monitor_window_time = #{monitorWindowTime,jdbcType=INTEGER}");
        }


        if (record.getCreator() != null) {
            sql.SET("creator = #{creator,jdbcType=VARCHAR}");
        }

        if (record.getCreatedTime() != null) {
            sql.SET("created_time = #{createdTime,jdbcType=TIMESTAMP}");
        }

        if (record.getMender() != null) {
            sql.SET("mender = #{mender,jdbcType=VARCHAR}");
        }

        if (record.getModifiedTime() != null) {
            sql.SET("modified_time = #{modifiedTime,jdbcType=TIMESTAMP}");
        }

        if (record.getIsDelete() != null) {
            sql.SET("is_delete = #{isDelete,jdbcType=BIT}");
        }

        sql.WHERE("id = #{id,jdbcType=BIGINT} and is_delete = 0");

        return sql.toString();
    }
}
